package mission1;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Files {

	public Files(){
		
	}
	
	/**
	 * lecture du fichier MPS
	 * @param path of the file to read
	 */
	public String read(String path){
		
		
		String chaine="";
		try{
			InputStream ips=new FileInputStream(path); 
			InputStreamReader ipsr=new InputStreamReader(ips);
			BufferedReader br=new BufferedReader(ipsr);
			String ligne;
			while ((ligne=br.readLine())!=null){
				chaine+=ligne+"\n";
			}
			br.close(); 
		}
		catch(Exception e){
			System.out.println(e.toString());
		}
		return chaine;
	}
	
	/**
	 * Ecriture du fichier de sortie
	 * @param path of the file to write and the chaine to write
	 */ 
	public void write(String chaine,String path){
		
		try {
			FileWriter fw = new FileWriter (path);
			BufferedWriter bw = new BufferedWriter (fw);
			PrintWriter fichierSortie = new PrintWriter (bw); 
			fichierSortie.print (chaine); 
			fichierSortie.close();
		}
		catch (Exception e){
			System.out.println(e.toString());
		}
	}
}
